package com.codingke.codingbookstore.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.codingke.codingbookstore.App;
import com.codingke.codingbookstore.R;
import com.codingke.codingbookstore.adapter.base.ViewHolder;
import com.codingke.codingbookstore.utils.AppUtils;
import com.codingke.codingbookstore.utils.Constant;
import com.codingke.codingbookstore.utils.NumberUtils;
import com.codingke.codingbookstore.vo.Orders;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.bitmap.core.BitmapSize;

import java.util.ArrayList;

/**
 * descreption:
 * company: codingke.com
 * Created by vince on 15/12/7.
 */
public class OrdersAdapter extends BaseAdapter{

    private Context context;
    private ArrayList<Orders> orderList;
    BitmapDisplayConfig config = new BitmapDisplayConfig();



    public void setOrderList(ArrayList<Orders> orderList) {
        this.orderList = orderList;
    }

    public OrdersAdapter(Context context, ArrayList<Orders> orderList){
        this.context = context;
        this.orderList = orderList;
        config.setBitmapMaxSize(new BitmapSize(72,72));
    }

    @Override
    public int getCount() {
        return orderList.size();
    }

    @Override
    public Object getItem(int position) {
        return orderList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.orders_item,null);
        }
        TextView textView5_subtotal = ViewHolder.getView(convertView,R.id.textView5_subtotal,null);
        TextView textView6_buyDate = ViewHolder.getView(convertView,R.id.textView6_buyDate,null);
        TextView textView7_total = ViewHolder.getView(convertView,R.id.textView7_total,null);
        TextView textView10_status = ViewHolder.getView(convertView,R.id.textView10_status,null);
        TextView textView11_bookname = ViewHolder.getView(convertView,R.id.textView11_bookname,null);
        ImageView imageView3_bookimage = ViewHolder.getView(convertView,R.id.imageView3_bookimage,null);

        Orders orders = orderList.get(position);
        textView5_subtotal.setText("总金额"+ NumberUtils.format(orders.getSubtotal())+"元");
        textView6_buyDate.setText(orders.getBuyDate());
        textView7_total.setText("数量 x"+orders.getTotal());
//        String status = "";
//        switch (orders.getStatus()){
//            case Constant.ORDER_NON_PAYMENT:
//                status = "未付款";
//                break;
//            case Constant.ORDER_PAYMENTS_RECEIVED:
//                status = "已付款";
//                break;
//            case Constant.ORDER_DELIVERED:
//                status = "已发货";
//                break;
//            case Constant.ORDER_RECEIVED_GOODS:
//                status = "已收货";
//                break;
//            case Constant.ORDER_HAS_BEEN_EVALUATED:
//                status = "已评价";
//                break;
//            default:
//                break;
//        }
        textView10_status.setText(AppUtils.getStatus(orders.getStatus()));
        textView11_bookname.setText(orders.getBookName());

        App.bitmapUtils.display(imageView3_bookimage,Constant.BMOBFILE_ROOT+orders.getBookImage(),config);
        return convertView;
    }
}
